﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMK.Framework.Model;
using XMK.Tadong.Data;
using XMK.Utils;
using XMK.Tadong.Model;
using XMK.Tadong.Model.Cond;

namespace XMK.Tadong.Biz
{
    public class Base_RM_SystemBiz
    {

        /// <summary>
        /// 取菜单
        /// </summary>
        /// <returns></returns>
        public ResponseInfo QueryMenuList()
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_SysMenuInfo>)data.GetMenuList();
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryMenuList:]" + ex.ToString());
            }
            return response;
        }
        /// <summary>
        /// 取菜单
        /// </summary>
        /// <returns></returns>
        public List<Base_SysMenuInfo> QueryMenuListForList()
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                return (List<Base_SysMenuInfo>)data.GetMenuList();
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryMenuList:]" + ex.ToString());
            }
            return null;
        }


        /// <summary>
        /// 取菜单
        /// </summary>
        /// <returns></returns>
        public ResponseInfo QueryMenuBind()
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_SysMenuInfo>)data.GetMenuBind();
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryMenuBind:]" + ex.ToString());
            }
            return response;
        }

        /// <summary>
        /// 取菜单
        /// </summary>
        /// <returns></returns>
        public ResponseInfo QuerySysMenuByButton(string menuId)
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_SysMenuInfo>)data.GetSysMenuByButton(menuId);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QuerySysMenuByButton:]" + ex.ToString());
            }
            return response;
        }

        /// <summary>
        /// 取菜单
        /// </summary>
        /// <param name="MenuID"></param>
        /// <returns></returns>
        public ResponseInfo GetMenuByMenuID(string MenuID)
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (Base_SysMenuInfo)data.GetMenuByMenuID(MenuID);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetMenuByMenuID:]" + ex.ToString());
            }
            return response;
        }

        /// <summary>
        /// 菜单修改
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo EditMenuByMenuID(Base_SysMenuCond cond)
        {
            if(string.IsNullOrEmpty(cond.MENU_ID)){
                cond.MENU_ID = Guid.NewGuid().ToString();
            }
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = data.EditMenuByMenuID(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[EditMenuByMenuID:]" + ex.ToString());
            }
            return response;
        }
        /// <summary>
        /// 按钮列表
        /// </summary>
        /// <returns></returns>
        public ResponseInfo ButtonList(PageInfo page, OrderInfo order)
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_ButtonInfo>)data.ButtonList(page, order);
                response.Page = page;
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[ButtonList:]" + ex.ToString());
            }
            return response;
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns></returns>
        public ResponseInfo RolesList()
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_RolesInfo>)data.RolesList();
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryMenuList:]" + ex.ToString());
            }
            return response;
        }

        /// <summary>
        /// 当前用户拥有的角色
        /// </summary>
        /// <param name="User_ID"></param>
        /// <returns></returns>
        public ResponseInfo GetRolesByID(string RoleID)
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (Base_RolesInfo)data.GetRolesByID(RoleID);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetRolesByID:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 编辑角色
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo EditRole(Base_RolesCond cond)
        {
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data =data.EditRole(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[EditRole:]" + ex.ToString());
            }
            return response;

        }
        
        /// <summary>
        /// 用户菜单
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public ResponseInfo GetUserMenuList()
        {
            string USER_ACCOUNT = LoginUserBiz.LoginUserID();
            ResponseInfo response = null;
            try
            {
                Base_RM_SystemData data = new Base_RM_SystemData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_SysMenuInfo>)data.GetUserMenuList(USER_ACCOUNT);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetUserMenuList:]" + ex.ToString());
            }
            return response;

        }
    }
}
